package com.sllp.C71S3TsllpShop.biz.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.sllp.C71S3TsllpShop.bean.Business;
import com.sllp.C71S3TsllpShop.bean.BusinessExample;
import com.sllp.C71S3TsllpShop.bean.Comment;
import com.sllp.C71S3TsllpShop.bean.CommentExample;
import com.sllp.C71S3TsllpShop.bean.Result;
import com.sllp.C71S3TsllpShop.bean.User;
import com.sllp.C71S3TsllpShop.bean.CommentExample.Criteria;
import com.sllp.C71S3TsllpShop.biz.CommentBiz;
import com.sllp.C71S3TsllpShop.dao.CommentMapper;

@Service
public class CommentBizImpl implements CommentBiz {

	@Resource
	private CommentMapper cm;
	
	
	/**
	 * 显示所有评论
	 * @return
	 */
	public List<Comment> findComment(User user){
		CommentExample ce=new CommentExample();
		Criteria c=ce.createCriteria();
		c.andUserEqualTo(user.getId());
		List<Comment> list=cm.selectByExampleWithBLOBs(ce);
		return list;
	}
	/**
	 * 显示同一商品的所有评论
	 */
	public List<Comment> findCommentByPro(int pid){
		CommentExample ce=new CommentExample();
		Criteria c=ce.createCriteria();
		c.andProductEqualTo(pid);
		List<Comment> list=cm.selectByExampleWithBLOBs(ce);
		return list;
	}
	
	
	/**
	 * 提交评论
	 */
	public Result addComment(Comment comment){
		int result=cm.insert(comment);
		if(result>0) {
			return new Result(1, "提交成功");
		}
		return new Result(0, "提交失败");
	}
}
